//
//  WriteToBeChangeTaskCell.m
//  MyProject
//
//  Created by Pei on 16/7/18.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "WriteToBeChangeTaskCell.h"
#import "UIImageView+WebCache.h"

@implementation WriteToBeChangeTaskCell
{
    UIImageView *headerImageView;
    UILabel *nameLbl;
    UILabel *dateLbl;
    UILabel *statusLbl;
    
    UIImageView *leftImageView;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = kDefaultBackgroundColor;
        
        UIView *leftLine = [[UIView alloc] init];
        leftLine.frame = CGRectMake(20.0f, 0.0f, 0.5f, 74.0f);
        leftLine.backgroundColor = kGreenColor;
        [self addSubview:leftLine];
        
        leftImageView = [[UIImageView alloc] init];
        leftImageView.frame = CGRectMake(13.0f, 10.0f, 56/4, 56/4);
        leftImageView.image = [UIImage imageNamed:@"right"];
        [self addSubview:leftImageView];
        
        UIView *contentView = [[UIView alloc] init];
        contentView.frame = CGRectMake(40.0f, 10.0f, kDeviceWidth-40.0f-10.0f, 54.0f);
        contentView.backgroundColor = kWhiteColor;
        [self addSubview:contentView];
        
        headerImageView = [[UIImageView alloc] init];
        headerImageView.frame = CGRectMake(10.0f, 10.0f, 34.0f, 34.0f);
        headerImageView.layer.masksToBounds = YES;
        headerImageView.layer.cornerRadius = 17.0f;
        headerImageView.backgroundColor = kGreenColor;
        [contentView addSubview:headerImageView];
        
        nameLbl = [[UILabel alloc] init];
        nameLbl.frame = CGRectMake(headerImageView.right+5.0f, headerImageView.origin.y, 80, Home_Big_Size);
        nameLbl.font = kAppFont(Home_Big_Size);
        nameLbl.text = @"HHHH";
        [contentView addSubview:nameLbl];
        
        dateLbl = [[UILabel alloc] init];
        dateLbl.frame = CGRectMake(nameLbl.right, headerImageView.origin.y, contentView.width-20.0f-headerImageView.width-5.0f-nameLbl.width, Home_Small_Size);
        dateLbl.font = kAppFont(Home_Small_Size);
        dateLbl.textColor = kGreenColor;
        dateLbl.text = @"2016-7-6";
        dateLbl.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:dateLbl];
        
        statusLbl = [[UILabel alloc] init];
        statusLbl.frame = CGRectMake(headerImageView.right+5.0f, nameLbl.bottom+5.0f, contentView.width-10.0f-headerImageView.width-5.0f, Home_Small_Size);
        statusLbl.font = kAppFont(Home_Small_Size);
        statusLbl.textColor = kGreenColor;
        //statusLbl.text = @"bbbb";
        //statusLbl.textAlignment = NSTextAlignmentRight;
        [contentView addSubview:statusLbl];
        
//        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@(%@)",@"拒绝",@"kkkkkkk"]];
//        NSString *AuditResultStr = @"拒绝";//[data valueForKey:@"AuditResult"];
//        if ([AuditResultStr isEqualToString:@"通过"]) {
//            [str addAttribute:NSForegroundColorAttributeName value:kRGB(176, 222, 146) range:NSMakeRange(0.0f,AuditResultStr.length)];
//            leftImageView.image = [UIImage imageNamed:@"right"];
//        }else{
//            [str addAttribute:NSForegroundColorAttributeName value:kRGB(239, 156, 161) range:NSMakeRange(0.0f,AuditResultStr.length)];
//            leftImageView.image = [UIImage imageNamed:@"wrong"];
//        }
//        
//        statusLbl.attributedText = str;
        
    }
    return self;
}

- (void)showWithData:(NSDictionary*)data{
    /*
     "AuditUser": "admin",
     "AuditID": 9,
     "AuditDate": "2016-05-24T16:49:09.797",
     "AuditDesc": "士大夫地方多少",
     "AuditResult": "拒绝"
     
     */
    //拒绝 和 通过
    
    nameLbl.text = [data valueForKey:@"AuditUser"];
    dateLbl.text = [[data valueForKey:@"AuditDate"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    statusLbl.text = [NSString stringWithFormat:@"%@(%@)",[data valueForKey:@"AuditResult"],[data valueForKey:@"AuditDesc"]];
    
    //176 222 146 tong   239 156 161 jujue
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@(%@)",[data valueForKey:@"AuditResult"],[data valueForKey:@"AuditDesc"]]];
    NSString *AuditResultStr = [data valueForKey:@"AuditResult"];
    if ([AuditResultStr isEqualToString:@"通过"]) {
        [str addAttribute:NSForegroundColorAttributeName value:kRGB(176, 222, 146) range:NSMakeRange(0.0f,AuditResultStr.length)];
        leftImageView.image = [UIImage imageNamed:@"right"];
    }else{
        [str addAttribute:NSForegroundColorAttributeName value:kRGB(239, 156, 161) range:NSMakeRange(0.0f,AuditResultStr.length)];
        leftImageView.image = [UIImage imageNamed:@"wrong"];
    }
    statusLbl.attributedText = str;
    
    NSString *nameStr = [data valueForKey:@"AuditUser"];
    NSString *urlStr = kAppApiGetImage(nameStr);
    NSString* encodedString = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    

    [headerImageView sd_setImageWithURL:[NSURL URLWithString:encodedString] placeholderImage:[UIImage imageNamed:@"normalDefault"]];
}


@end
